home *** CD-ROM | disk | FTP | other *** search
/ Enter 2006 September / Enter 09 2006.iso / Internet / SpamExperts Home 1.1 / SpamExperts Home.exe / lib / spamexperts.modules / persistent / interfaces.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2006-07-14  |  10.4 KB  |  257 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. '''Persistence Interfaces
  5.  
  6. $Id: interfaces.py 40668 2005-12-09 17:15:11Z tim_one $
  7. '''
  8. from zope.interface import Interface
  9. from zope.interface import Attribute
  10.  
  11. class IPersistent(Interface):
  12.     """Python persistent interface
  13.  
  14.     A persistent object can be in one of several states:
  15.  
  16.     - Unsaved
  17.  
  18.       The object has been created but not saved in a data manager.
  19.  
  20.       In this state, the _p_changed attribute is non-None and false
  21.       and the _p_jar attribute is None.
  22.  
  23.     - Saved
  24.  
  25.       The object has been saved and has not been changed since it was saved.
  26.  
  27.       In this state, the _p_changed attribute is non-None and false
  28.       and the _p_jar attribute is set to a data manager.
  29.  
  30.     - Sticky
  31.  
  32.       This state is identical to the saved state except that the
  33.       object cannot transition to the ghost state.  This is a special
  34.       state used by C methods of persistent objects to make sure that
  35.       state is not unloaded in the middle of computation.
  36.  
  37.       In this state, the _p_changed attribute is non-None and false
  38.       and the _p_jar attribute is set to a data manager.
  39.  
  40.       There is no Python API for detecting whether an object is in the
  41.       sticky state.
  42.  
  43.     - Changed
  44.  
  45.       The object has been changed.
  46.  
  47.       In this state, the _p_changed attribute is true
  48.       and the _p_jar attribute is set to a data manager.
  49.  
  50.     - Ghost
  51.  
  52.       the object is in memory but its state has not been loaded from
  53.       the database (or its state has been unloaded).  In this state,
  54.       the object doesn't contain any application data.
  55.  
  56.       In this state, the _p_changed attribute is None, and the _p_jar
  57.       attribute is set to the data manager from which the object was
  58.       obtained.
  59.  
  60.     In all the above, _p_oid (the persistent object id) is set when
  61.     _p_jar first gets set.
  62.  
  63.     The following state transitions are possible:
  64.  
  65.     - Unsaved -> Saved
  66.  
  67.       This transition occurs when an object is saved in the
  68.       database.  This usually happens when an unsaved object is added
  69.       to (e.g. as an attribute or item of) a saved (or changed) object
  70.       and the transaction is committed.
  71.  
  72.     - Saved  -> Changed
  73.       Sticky -> Changed
  74.       Ghost  -> Changed
  75.  
  76.       This transition occurs when someone sets an attribute or sets
  77.       _p_changed to a true value on a saved, sticky or ghost object.  When
  78.       the transition occurs, the persistent object is required to call the
  79.       register() method on its data manager, passing itself as the
  80.       only argument.
  81.  
  82.       Prior to ZODB 3.6, setting _p_changed to a true value on a ghost object
  83.       was ignored (the object remained a ghost, and getting its _p_changed
  84.       attribute continued to return None).
  85.  
  86.     - Saved -> Sticky
  87.  
  88.       This transition occurs when C code marks the object as sticky to
  89.       prevent its deactivation.
  90.  
  91.     - Saved -> Ghost
  92.  
  93.       This transition occurs when a saved object is deactivated or
  94.       invalidated.  See discussion below.
  95.  
  96.     - Sticky -> Saved
  97.  
  98.       This transition occurs when C code unmarks the object as sticky to
  99.       allow its deactivation.
  100.  
  101.     - Changed -> Saved
  102.  
  103.       This transition occurs when a transaction is committed.  After
  104.       saving the state of a changed object during transaction commit,
  105.       the data manager sets the object's _p_changed to a non-None false
  106.       value.
  107.  
  108.     - Changed -> Ghost
  109.  
  110.       This transition occurs when a transaction is aborted.  All changed
  111.       objects are invalidated by the data manager by an abort.
  112.  
  113.     - Ghost -> Saved
  114.  
  115.       This transition occurs when an attribute or operation of a ghost
  116.       is accessed and the object's state is loaded from the database.
  117.  
  118.     Note that there is a separate C API that is not included here.
  119.     The C API requires a specific data layout and defines the sticky
  120.     state.
  121.  
  122.  
  123.     About Invalidation, Deactivation and the Sticky & Ghost States
  124.  
  125.     The sticky state is intended to be a short-lived state, to prevent
  126.     an object's state from being discarded while we're in C routines.  It
  127.     is an error to invalidate an object in the sticky state.
  128.  
  129.     Deactivation is a request that an object discard its state (become
  130.     a ghost).  Deactivation is an optimization, and a request to
  131.     deactivate may be ignored.  There are two equivalent ways to
  132.     request deactivation:
  133.  
  134.           - call _p_deactivate()
  135.           - set _p_changed to None
  136.  
  137.     There are two ways to invalidate an object:  call the
  138.     _p_invalidate() method (preferred) or delete its _p_changed
  139.     attribute.  This cannot be ignored, and is used when semantics
  140.     require invalidation.  Normally, an invalidated object transitions
  141.     to the ghost state.  However, some objects cannot be ghosts.  When
  142.     these objects are invalidated, they immediately reload their state
  143.     from their data manager, and are then in the saved state.
  144.  
  145.     """
  146.     _p_jar = Attribute('The data manager for the object.\n\n        The data manager implements the IPersistentDataManager interface.\n        If there is no data manager, then this is None.\n        ')
  147.     _p_oid = Attribute("The object id.\n\n        It is up to the data manager to assign this.\n        The special value None is reserved to indicate that an object\n        id has not been assigned.  Non-None object ids must be non-empty\n        strings.  The 8-byte string '\x00'*8 (8 NUL bytes) is reserved to\n        identify the database root object.\n        ")
  148.     _p_changed = Attribute("The persistent state of the object.\n\n        This is one of:\n\n        None -- The object is a ghost.\n\n        false but not None -- The object is saved (or has never been saved).\n\n        true -- The object has been modified since it was last saved.\n\n        The object state may be changed by assigning or deleting this\n        attribute; however, assigning None is ignored if the object is\n        not in the saved state, and may be ignored even if the object is\n        in the saved state.\n\n        At and after ZODB 3.6, setting _p_changed to a true value for a ghost\n        object activates the object; prior to 3.6, setting _p_changed to a\n        true value on a ghost object was ignored.\n\n        Note that an object can transition to the changed state only if\n        it has a data manager.  When such a state change occurs, the\n        'register' method of the data manager must be called, passing the\n        persistent object.\n\n        Deleting this attribute forces invalidation independent of\n        existing state, although it is an error if the sticky state is\n        current.\n        ")
  149.     _p_serial = Attribute('The object serial number.\n\n        This member is used by the data manager to distiguish distinct\n        revisions of a given persistent object.\n\n        This is an 8-byte string (not Unicode).\n        ')
  150.     
  151.     def __getstate__():
  152.         '''Get the object data.
  153.  
  154.         The state should not include persistent attributes ("_p_name").
  155.         The result must be picklable.
  156.         '''
  157.         pass
  158.  
  159.     
  160.     def __setstate__(state):
  161.         '''Set the object data.
  162.         '''
  163.         pass
  164.  
  165.     
  166.     def _p_activate():
  167.         '''Activate the object.
  168.  
  169.         Change the object to the saved state if it is a ghost.
  170.         '''
  171.         pass
  172.  
  173.     
  174.     def _p_deactivate():
  175.         '''Deactivate the object.
  176.  
  177.         Possibly change an object in the saved state to the
  178.         ghost state.  It may not be possible to make some persistent
  179.         objects ghosts, and, for optimization reasons, the implementation
  180.         may choose to keep an object in the saved state.
  181.         '''
  182.         pass
  183.  
  184.     
  185.     def _p_invalidate():
  186.         '''Invalidate the object.
  187.  
  188.         Invalidate the object.  This causes any data to be thrown
  189.         away, even if the object is in the changed state.  The object
  190.         is moved to the ghost state; further accesses will cause
  191.         object data to be reloaded.
  192.         '''
  193.         pass
  194.  
  195.  
  196.  
  197. class IPersistentNoReadConflicts(IPersistent):
  198.     
  199.     def _p_independent():
  200.         '''Hook for subclasses to prevent read conflict errors.
  201.  
  202.         A specific persistent object type can define this method and
  203.         have it return true if the data manager should ignore read
  204.         conflicts for this object.
  205.         '''
  206.         pass
  207.  
  208.  
  209.  
  210. class IPersistentDataManager(Interface):
  211.     '''Provide services for managing persistent state.
  212.  
  213.     This interface is used by a persistent object to interact with its
  214.     data manager in the context of a transaction.
  215.     '''
  216.     
  217.     def setstate(object):
  218.         """Load the state for the given object.
  219.  
  220.         The object should be in the ghost state. The object's state will be
  221.         set and the object will end up in the saved state.
  222.  
  223.         The object must provide the IPersistent interface.
  224.         """
  225.         pass
  226.  
  227.     
  228.     def oldstate(obj, tid):
  229.         """Return copy of 'obj' that was written by transaction 'tid'.
  230.  
  231.         The returned object does not have the typical metadata (_p_jar, _p_oid,
  232.         _p_serial) set. I'm not sure how references to other peristent objects
  233.         are handled.
  234.  
  235.         Parameters
  236.         obj: a persistent object from this Connection.
  237.         tid: id of a transaction that wrote an earlier revision.
  238.  
  239.         Raises KeyError if tid does not exist or if tid deleted a revision of
  240.         obj.
  241.         """
  242.         pass
  243.  
  244.     
  245.     def register(object):
  246.         '''Register an IPersistent with the current transaction.
  247.  
  248.         This method must be called when the object transitions to
  249.         the changed state.
  250.  
  251.         A subclass could override this method to customize the default
  252.         policy of one transaction manager for each thread.
  253.         '''
  254.         pass
  255.  
  256.  
  257.